import 'package:flutter/material.dart';

class KeepAliveFutureBuilder<T> extends StatefulWidget {
  final Future<T> future;
  final AsyncWidgetBuilder<T> builder;

  KeepAliveFutureBuilder({this.future, this.builder});

  @override
  _KeepAliveFutureBuilderState<T> createState() => _KeepAliveFutureBuilderState<T>();
}

class _KeepAliveFutureBuilderState<T> extends State<KeepAliveFutureBuilder>
    with AutomaticKeepAliveClientMixin {
  Future<T> future;

  @override
  void initState() {
    future = widget.future;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return FutureBuilder<T>(
      future: future,
      builder: widget.builder,
    );
  }

  @override
  void didUpdateWidget(KeepAliveFutureBuilder oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  @override
  bool get wantKeepAlive => true;
}
